
import { Message } from 'element-ui';

// 下载文件流
export function requestDown(res, fileName) {
	// 对下载的流进行处理，直接从浏览器下载下来
	const content = res;
	const blob = new Blob([content], {
		// 下载的文件格式自己在这边更改type的值就好了
		type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	});
	if ("download" in document.createElement("a")) {
		const elink = document.createElement("a");
		elink.download = fileName;
		elink.style.display = "none";
		elink.href = URL.createObjectURL(blob);
		document.body.appendChild(elink);
		elink.click();
		URL.revokeObjectURL(elink.href);
		document.body.removeChild(elink);

		Message.success("下载成功，请查看")
	} else {
		navigator.msSaveBlob(blob, fileName);
	}
}
